// const Koa = require("koa");
// const bodyParser = require("koa-bodyparser");
// const Router = require("koa-router");

// const static = require("koa-static");
// var jwt = require('jsonwebtoken');
import Koa from 'koa'
import Router from 'koa-router'
import bodyParser from 'koa-bodyparser'
import koaStatic from "koa-static"
import admin from "./route/admin.js"
import api from "./route/api.js"


const app = new Koa();


app.use(bodyParser());

app.use(koaStatic("./public", "/"));

app.use(async (ctx, next) => {
    console.log(ctx.method, ctx.host, ctx.url)
    var sTime = Date.now();
    await next();
    console.log(Date.now() - sTime);

})




//装载所有子路由
let router = new Router()
router.use('/admin', admin.routes(), admin.allowedMethods())
router.use('/api', api.routes(), api.allowedMethods())


//加载路由中间件
app.use(router.routes()).use(router.allowedMethods());

app.listen(3000);